
#ifndef _ISOFTBODYCONCAVEALGORITHM_H_
#define _ISOFTBODYCONCAVEALGORITHM_H_

#include <BSoftBody>
#include "IAlgorithm.h"
#include "IHashMap.h"
#include "ISpaceTree.h"
#include "member_BRestraint.h"

struct TrigIndex
{
	int m_PartIdTriangleIndex;
	class BShape* m_childShape;

	TrigIndex(int partId, int triangleIndex, BShape* shape)
	{
		m_PartIdTriangleIndex = (partId << (31 - 10)) | triangleIndex;
		m_childShape = shape;
	}

	int getTriangleIndex() const
	{
		unsigned int x = 0;
		unsigned int y = (~(x & 0)) << (31 - 10);
		return (m_PartIdTriangleIndex & ~(y));
	}
	int getPartId() const
	{
		return (m_PartIdTriangleIndex >> (31 - 10));
	}
	int getUid() const
	{
		return m_PartIdTriangleIndex;
	}
};

class SoftBodyTriangleCallback
{
public:
	BSoftBody* m_softBody;
	BBody* m_triBody;

	BVector m_aabbMin;
	BVector m_aabbMax;

	BReal m_collisionMarginTriangle;

	int m_triangleCount;

	void setTimeStepAndCounters(BMesh* mesh, BReal collisionMarginTriangle, const BBody* triObjWrap);

	virtual void processTriangle();

	inline const BVector& getAabbMin() const
	{
		return m_aabbMin;
	}
	inline const BVector& getAabbMax() const
	{
		return m_aabbMax;
	}
};

class ISoftBodyConcaveAlgorithm : public IAlgorithm
{
public:
	ISoftBodyConcaveAlgorithm();
	~ISoftBodyConcaveAlgorithm();

	virtual void caculate() override;
	virtual void timeImpact() override;

private:
	bool		m_isSwapped;
	SoftBodyTriangleCallback m_softBodyTriangleCallback;

};

#endif
